<?php
App :: import('I19n', 'l10n');
App :: uses('AuthComponent', 'Controller/Component');
class AppController extends Controller {

	public $helpers = array (
		"Html",
		"Form",
		"Session",
		"Cache",
		"Js" => array (
			"Jquery"
		)
	);

	public $components = array (
		'Session',
		'Cookie',
		'Auth' => array (
			'loginRedirect' => array (
				'controller' => 'products',
				'action' => 'index'
			),
			'logoutRedirect' => array (
				'controller' => 'pages',
				'action' => 'index',
				'home'
			),
			'authError' => "Soory for that looks like you don't have the permission to access this page.",
			'authenticate' => array (
				'Form' => array (
					"userModel" => "User",
					"fields" => array (
						"username" => "username",

					)
				)
			)
		)
	);

	public function beforeFilter() {
		Authcomponent::setSessionKey("Auth.User");
		$this->Auth->deny("*");
		$this->Auth->allow(array("login","display"));
	}

	public function isAuthorized($user) {
		if (isset ($user['role']) && $user['role'] === 'admin') {
			return true; //Admin can access every action
		}
		return false; // The rest don't
	}
}
?>